package core;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class GoldDataRead {

	private List<PriceData> allDatas = new ArrayList<PriceData>();

	public GoldDataRead(String fileName, int skip, int maxLines) {
		try {
			FileReader fr = new FileReader(fileName);// ����FileReader����������ȡ�ַ���
			BufferedReader br = new BufferedReader(fr); // ����ָ���ļ�������

			String myreadline; // ����һ��String���͵ı���,����ÿ�ζ�ȡһ��
			br.readLine();
			// skip beginning lines
			while (br.ready() && (skip > 0)) {
				br.readLine();
				--skip;
			}

			int count = 0;
			while (br.ready()) {
				myreadline = br.readLine();// ��ȡһ��
				PriceData dd = new PriceData(myreadline);
				allDatas.add(dd);
				// System.out.println(myreadline);// ����Ļ�����
				count++;
				if ((0 < maxLines) && (count > maxLines)) {
					break;
				}
			}

			System.out.println("From Date: " + printDate(allDatas.get(0).time));
			System.out.println("To Date: " + printDate(allDatas.get(allDatas.size() - 1).time)
							+ "\r\n");

			br.close();
			br.close();
			fr.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public List<PriceData> getAllDatas() {
		return allDatas;
	}

	public static String printDate(Date time) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // ��date�������ڸ�ʽ��
		String sss = df.format(time);

		return sss;
	}

	public static void main(String[] args) {
		new GoldDataRead("data/XAUUSD.txt", 0, -1);
	}
}
